package com.education.basic.service.impl;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import com.education.basic.entity.TeachInfo;
import com.education.basic.service.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.education.basic.entity.FeeInfo;
import com.education.basic.entity.Score;
import com.education.basic.entity.Student;
import com.education.basic.resource.Courses;
import com.education.basic.resource.MajorFee;

@Service("studentService")
public class StudentServiceImpl extends BaseServiceImpl<Student> implements StudentService
{
    @Resource
	private FeeInfoService feeInfoService;

    @Resource
	private ScoreService scoreService;
    @Resource
    private TeachInfoService teachInfoService;

	@Override
	@Transactional
	public Student newStudent(Student s)
	{
		this.saveObject(s);
		FeeInfo info = new FeeInfo(s.getStuNum(),s.getName(),new BigDecimal(MajorFee.getMajorFee(s.getProfessionId())),false);
		feeInfoService.saveObject(info);
		List<Courses> courses = Courses.queryCourseByMajorCodeAndCoursesType(s.getProfessionId(), null);
		for(Courses c : courses)
		{
            String courseCode = c.getCode();
            TeachInfo info2 = teachInfoService.findTeachInfoByCourseCode(courseCode);
            Score score = null;
            if(info2==null)
            {
                 score = new Score(s.getStuNum(), s.getName(), c.getCode(), c.getName(), 0, false, null, null);
            }else
            {
                 score = new Score(s.getStuNum(), s.getName(), c.getCode(), c.getName(), 0, false, info2.getEmpno(), info2.getTeacherName());
            }
			scoreService.saveObject(score);
		}
		return s;
	}

    @Override
    public List<Student> queryStudentByMajorCode(String majorCode) {
        return null;
    }

	
}
